package com.kch.web.controller.system;


import com.github.pagehelper.PageHelper;
import com.kch.common.core.controller.BaseController;
import com.kch.common.core.domain.AjaxResult;
import com.kch.common.core.page.TableDataInfo;
import com.kch.framework.util.ShiroUtils;
import com.kch.system.domain.SysUser;
import com.kch.system.req.UserCollectBrowseReq;
import com.kch.system.service.IUserCollectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@Api(tags = "用户收藏")
@ResponseBody
@RequestMapping("/system/user/")
public class UserCollectController extends BaseController {

    @Autowired
    private IUserCollectService userCollectService;

    @PostMapping("/collect")
    @ApiOperation("用户收藏, busId:方案/需求/问题/专家id不能为空, cloumnCode:栏目编码不能为空")
    public AjaxResult collect(@RequestBody @Validated UserCollectBrowseReq req){
        SysUser sysUser = ShiroUtils.getSysUser();
        userCollectService.insertUserCollect(req, sysUser);
        return AjaxResult.success();
    }

    @GetMapping("/getCollect")
    @ApiOperation("查询用户收藏")
    public TableDataInfo getCollect(@RequestParam Integer pageNum, @RequestParam Integer pageSize){
        PageHelper.startPage(pageNum, pageSize);
        return getDataTable(userCollectService.selectCollectPage(ShiroUtils.getSysUser()));
    }
}
